#ifndef LOGGER_HPP
#define LOGGER_HPP

#include <QtCore>
#include <QtGui>
#include <Eigen/Core>

using namespace Eigen;

class Logger : public QObject {
  Q_OBJECT

  public:
    Logger();
    Logger(QWidget *parent);
    ~Logger();
    void save(const QString &fileName);
    void save(const char *fileName);
    void append(const QString &message);
    void append(const char *message);
    Logger & operator<<(signed short i);
    Logger & operator<<(float f);
    Logger & operator<<(const QString & string);
    Logger & operator<<(char c);
    Logger & operator<<(unsigned short i);
    Logger & operator<<(signed int i);
    Logger & operator<<(unsigned int i);
    Logger & operator<<(signed long i);
    Logger & operator<<(unsigned long i);
    Logger & operator<<(qlonglong i);
    Logger & operator<<(qulonglong i);
    Logger & operator<<(double f);
    Logger & operator<<(const QByteArray & array);
    Logger & operator<<(const char * string);
    Logger & operator<<(Logger &(*func)(Logger &));
    Logger & operator<<(const Vector3d &vector);
    //Logger & appendTableRow(QStringList &columns,QList<int> &columnWidths);
    Logger & appendTableRow(QStringList &columns,int columnWidth);
    void flush();
  public slots:
    void show();
    void setEnabled(bool enabled);
  private slots:
    void save();
    void clear();
    void scrollToBottom(int min,int max);
    void filter(const QString &pattern);
  private:
    void init();

    bool enabled;
    bool hasGUI;
    QStringList *messages;
    QStringListModel *listModel;
    QSortFilterProxyModel *filterModel;
    QDialog *logWindow;
    QListView *listView;
    QStringList *buffer;
    QLabel *filterLabel;
    QLineEdit *filterInput;
};

Logger & endl(Logger &logger);

#endif
